#define _CRT_SECURE_NO_WARNINGS 1
#include"class.h"

//class Date {
//public:
//	void Init(int year, int month, int day) {
//		_year = year;
//		_month = month;
//		_day = day;
//	}
//	void Print();
//private:
//	int _year;
//	int _month;
//	int _day;
//};
//void Date::Print() {
//	cout << _year << "/" << _month << '/' << _day << endl;
//}
//int main() {
//	Date D;
//	D.Init(2025, 8, 31);
//	D.Print();
//	return 0;
//}
typedef int STDataType;
class stack {
public:
	void Init(int n = 4)
	{
		_a = (STDataType*)malloc(sizeof(STDataType) * n);
		if (_a == nullptr)
		{
			perror("malloc fail");
			exit(1);
		}
		_capacity = n;
		_top = 0;
	}
	void Push(STDataType x)
	{
		if (_top == _capacity)
		{
			int newcapacity = 2 * _capacity;
			STDataType* tmp = (STDataType*)realloc(_a, newcapacity * sizeof(STDataType));
			if (tmp == NULL)
			{
				perror("realloc fail");
				exit(1);
			}
			_a = tmp;
			_capacity = newcapacity;
		}
		_a[_top++] = x;
	}
	void Pop()
	{
		assert(_top > 0);
		_top--;
	}
	bool empty()
	{
		return _top==0;
	}
	int top()
	{
		assert(_top);
		return _a[_top - 1];
	}
	void Destroy()
	{
		free(_a);
		_a = nullptr;
		_top = _capacity = 0;
	}
private:
	STDataType* _a;
	int _capacity;
	int _top;
};
int main() {
	stack s1;
	s1.Init();
	s1.Push(1);
	s1.Push(2);
	s1.Push(3);
	s1.Push(4);
	s1.Push(5);

	while (!s1.empty())
	{
		cout << s1.top() << ' ';
		s1.Pop();
	}
	s1.Destroy();
	return 0;
}